home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Developer Helper 1: Phil & Dave's Excellent CD
/
Excellent CD HFS.raw
/
Moof
/
Goodies
/
MPW Goodies
/
MPW Goodies⁄DTS
/
CheckWindowOut
< prev
next >
Wrap
Text File
|
2022-08-05
|
4KB
|
168 lines
# CheckWindowOut - check a window out for modification
#
# Usage: CheckWindowOut window
#
# Status: CheckWindowOut may return the following status values:
#
# 0 the window was checked out
# 1 error
# 4 the user canceled
#
# CheckWindowOut uses the ProjectInfo command to determine the
# parent project for a file open as a window. Once this project
# has been determined, the file can be properly checked out.
# A dialog allows the user to type in a short comment that
# indicates what the reason for checking the file out was.
# This will be logged into the project, and, if the file has
# a LastChange marker, will be logged into the file.
#
# © 1988, 1989 Apple Computer, Inc.
# All rights reserved.
Set Exit 0
# the following helps to debug until MPW sends echos to Dev:Console instead of Dev:StdErr
If {Echo} == 1
Set somewhere "∑∑ '{Worksheet}∂'"
Else
Set somewhere '∑ Dev:Null'
End
Begin
Set Comment "{SystemFolder}Comment" # file to compose comment in
Set Window "{1}"
# get short name of window
If "{Window}" !~ /:*([¬:]+:*)*([¬:]+)®1/
Exit 1
End
Set Short "{®1}" # get short name for dialogs
Set Cant "“{Short}” can’t be checked out "
# check what project the window belongs to
Set Info "`ProjectInfo "{Window}"`"
### If "{Info}" !~ /≈Project: (≈∫)®1 ≈/
If "{Info}" !~ /≈Project: (≈)®1 Checked out: ≈/
Alert "{Cant}because it doesn’t belong to a project."
Exit 1
End
Set Project "{®1}"
# check if the window is already checked out
If "{Info}" =~ /[¬,]+,[¬ ∂t]+∂+≈/
Alert "{Cant}again because it’s already checked out for modification."
Exit 1
End
# check if the window is ModifyReadOnly'd
If "{Info}" =~ /[¬,]+,[¬ ∂t]+∂*≈/
Alert "{Cant}because it’s a modified read-only copy."
Exit 1
End
# get the version that is checked out
If "{Info}" !~ /[¬,]+,([0-9]+)®1≈/
Exit 1
End
Set OldVersion {®1}
# check if the project is mounted
ProjectInfo -project "{Project}" -only ∑ Dev:Null
If {Status} != 0
Alert "{Cant}because the project “{Project}” is not mounted."
Exit 1
End
# see if the file is already checked out
Set Info "`ProjectInfo -latest -project "{Project}" "{Short}"`"
If "{Info}" == ""
Alert "{Cant}because it isn’t really in the project “{Project}”."
Exit 1
Else If "{Info}" =~ /≈r: (?*[¬ ])®1 +Checked out≈/
Set Owner "{®1}"
If "{Owner}" == "{User}"
Alert "{Cant}because you have already checked it out elsewhere."
Exit 1
Else
Alert "{Cant}because it has already been checked out by {Owner}."
Exit 1
End
End
# get position within window so we can return to it later
If `Position -c "{Window}"` !~ /([0-9]+)®1,([0-9]+)®2/
Exit 1
End
Set SelectionStart {®1}
Set SelectionSize `Evaluate {®2}-{®1}`
# get a comment about the change
Set IgnoreCmdPeriod 1
Echo -n "{DefaultComment}" | CoolRequest -d -q "What are you are going to change in “{Short}”?" >"{Comment}"
Set CommentStatus {Status}
Set IgnoreCmdPeriod 0
If {CommentStatus} != 0
Delete -i "{Comment}"
If {CommentStatus} == 4
Exit 4
End
Exit 1
End
# check the file out
# *** what about introducing a new branch?
# *** what about entering a "task"?
### CheckOut -cf "{Comment}" -m "{Window}" || Set CheckOutStatus {Status}
CheckOut -cf "{Comment}" -m -project "{Project}" "{Window}" || Set CheckOutStatus {Status}
If {CheckOutStatus} != 0
Delete -i "{Comment}"
# *** need to check this more closely (Cancel from dialog gets here)
Alert "I confused: CheckOut failed!"
End
Find •!{SelectionStart}:§!{SelectionSize} "{Window}"
If {ProjectHeaders}
Mark -y § OldSelection "{Window}"
# *** what should we do if there is no marker?
# *** we can create a header, or not put the change in the file at all
AddChange "{Window}" "{Comment}"
Find OldSelection "{Window}"
Unmark OldSelection "{Window}"
Save "{Window}"
End
Delete -i "{Comment}"
# check if the version is too new
Set Info "`ProjectInfo "{Window}"`"
If "{Info}" !~ /[¬,]+,([0-9]+)®1≈/
Exit 1
End
Set NewVersion {®1}
Set Increment `Evaluate {NewVersion} - {OldVersion}`
If {Increment} > 0
If {Increment} == 1
Alert "The “{Short}” that you just checked out is a version newer than your old copy."
Else
Alert "The “{Short}” that you just checked out is {Increment} versions newer than your old copy."
End
End
End {somewhere}